using System;
using System.IO;
using NMock2;
using NMock2.Monitoring;


namespace NMockExtensions
{
    public class Remember
    {
        public static IAction EventAdd = new EventAddAction();
        public static IAction EventRemove = new EventRemoveAction();
        internal static ListOfMocksWithEvents mocksWithEvents = new ListOfMocksWithEvents();

        #region Nested type: EventAddAction

        private class EventAddAction : IAction
        {
            public void DescribeTo(TextWriter writer)
            {
                writer.WriteLine("EventAdd for something");
            }

            public void Invoke(Invocation invocation)
            {
                mocksWithEvents.AddHandler(invocation.Receiver, invocation.Method.Name.Substring("add_".Length),
                                           (Delegate) invocation.Parameters[0]);
            }
        }

        #endregion

        #region Nested type: EventRemoveAction

        private class EventRemoveAction : IAction
        {
            public void DescribeTo(TextWriter writer)
            {
                writer.WriteLine("EventRemove for something");
            }

            public void Invoke(Invocation invocation)
            {
                mocksWithEvents.RemoveHandler(invocation.Receiver, invocation.Method.Name.Substring("remove_".Length),
                                              (Delegate) invocation.Parameters[0]);
            }
        }

        #endregion
    }
}